<?php
class medalController extends base
{

    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 获取新增自定义勋章
     */
    public function dogetCustomMedal()
    {
        $medalDv = common::request('dataDv', 'G', 0);
        $this->result['result'] = $this->load('medal')->getCustomMedal($medalDv);
    }
    /**
     * 获取用户所有勋章
     */
    public function dogetMyMedal()
    {
        $uid = common::request('uid', 'G');
        $uid = empty($uid) ? $this->uid : $uid;
        if($uid)
        {
            $this->result['result'] = $this->load('medal')->getUserMedals($uid);
        }
        else
        {
            $_ENV['error']->getErrors(201);
            exit;
        }
    }
    /**
     * 获取勋章判断依据相关数据
     */
    public function domedalBasisData()
    {
        if($this->uid)
        {
            $this->result['result'] = $this->load('medal')->getMedalBasisDataOld($this->uid);
        }
        else
        {
            $_ENV['error']->getErrors(201);
            exit;
        }
    }
    /**
     * 获取跑步记录新增勋章
     */
    public function donewRecordMedal()
    {
        if($this->uid)
        {
            $this->result['result']['medals'] = $this->load('medal')->getNewRecordMedal($this->uid);
        }
        else
        {
            $_ENV['error']->getErrors(201);
            exit;
        }
    }
    
    /*
     * 获得所有勋章
     */
    public function dogetMedals(){
        $dataDv = common::request('dataDv', 'G', 0);
        $cate = common::request('cate','G');
        $uid = $this->uid;
        
        if(empty($uid)){
            $_ENV['error']->getErrors(201);
            exit;
        }
        
        $medal_mod = $this->load('medal');
        $medals = $medal_mod->getMedals($dataDv,$cate);
        $basisData = $medal_mod->getMedalBasisData($uid);
        foreach($medals as $medal){
            $medal['updatetime'] > $dataDv && $dataDv = $medal['updatetime'];
        }
        
        $this->result['result'] = compact('medals','basisData','dataDv');
    }
}